<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加文章</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/layui/css/layui.css"/>
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/style/mylay.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="close_btn" onclick="history.back(-1);">×</div>
            <form class="layui-form">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本内容</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span>*</span> 标题：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="m_title" lay-verify="required" value="{$data.title}" placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">图片</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="m_pic" name="m_pic" placeholder="请上传图片" value="{$data.pic}" autocomplete="off" class="layui-input">
                                </div>
                                <button class="layui-btn" type="button" id="btn_upload">上传</button>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">内容：</label>
                                <div class="layui-input-block">
                                    <script id="m_info" type="text/plain">{$data.info}</script>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否发布：</label>
                                <div class="layui-input-block">
                                    <if condition="$data['is_show']==1">
                                        <input type="checkbox" name="m_show" value="1" checked lay-skin="switch">
                                        <else/>
                                        <input type="checkbox" name="m_show" value="1" lay-skin="switch">
                                    </if>
                                </div>
                            </div>
                            <input type="hidden" name="id" value="{$data.id}">
                        </div>

                    </div>
                </div>
                <input type="hidden" name="m_id" id="m_id" value="0">
                <div class="layui-form-item layui-layout-admin" style="border: 0;padding: 0;">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit lay-filter="LAY-submit" id="LAY-submit">确认添加</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
<script src="/Application/iframe/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/Application/iframe/assets/libs/layuiadmin/layui/layui.js"></script>

<script type="text/javascript" charset="utf-8" src="/Application/iframe/uedit/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Application/iframe/uedit/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/Application/iframe/uedit/lang/zh-cn/zh-cn.js"></script>
<script>
    var Ue = UE.getEditor('m_info', {
        initialFrameWidth: 1000, //初始化宽度
        initialFrameHeight: 400,  //初始化高度
        zIndex: 0,  //初始化高度
    });
</script>
<script>
    var url = '/admin/Announcement';
    layui.config({
        base: '/Application/iframe/assets/libs/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'upload', 'layedit'], function(){
        var $ = layui.$
            ,upload = layui.upload
            ,form = layui.form
            ,layedit = layui.layedit;

        var index = layedit.build('editor');
        //图片
        upload.render({
            elem: '#btn_upload'
            ,url: "{:U('upload/uploadFile')}"
            ,data: {dir: 'article'}
            ,accept: 'images'
            ,before: function () {
                layer.load();
            }
            ,done: function(res){
                layer.closeAll();
                if(res.code == 1001) {
                    $('#m_pic').val(res.file);
                    $('#yl_pic').attr('src',res.src);
                }
                else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                layer.closeAll();
                layer.msg('请求异常');
            }
        });
        //预览
        $('#btn_preview').click(function () {
            layer.open({
                type: 1,
                shade: false,
                title: false,
                content: $('#pic')
            });
        });
        /* 监听提交 */
        form.on('submit(LAY-submit)', function(data){
            var field = data.field; //获取提交的字段
            var m_info = UE.getEditor('m_info').getContent();
            var m_top = 0,m_show = 0;
            if (field.m_show != undefined){
                m_show = field.m_show;
            }

            $.ajax({
                type:"post",
                url:url + "/save.html",
                data: {
                    title:field.m_title,
                    pic:field.m_pic,
                    info:m_info,
                    is_show:m_show,
                    id:field.id,
                },
                dataType:"json",
                beforeSend: function () {
                    $('#LAY-submit').attr("disabled",true);
                    layer.load(1);
                },
                success:function(res){
                    layer.closeAll(); //关闭弹层
                    if(res.code == 1001){
                        layer.msg('操作成功', {
                            time: 2000
                        }, function(){
                            location.href = url + "/index.html";
                        });
                    }
                    else {
                        $('#LAY-submit').attr("disabled",false);
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });

    });
</script>